﻿using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MongoDB.Bson;
using MongoDB.Driver;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.DataLayer.Shared;

namespace Sustainalytics.DataLayer.Tests.Shared
{
    [TestClass]
    public class OrderingUnitTests
    {

        private Ordering<CorporateData> _sut;

        [TestMethod]
        public void Ordering_With_One_Expression_Test()
        {
            _sut = Ordering<CorporateData>.Ascending(x => x.CompanyType);
            var result = _sut.ToMongoSortBy().ToBson();
            var expectedResult = Builders<CorporateData>.Sort.Ascending(x => x.CompanyType).ToBson();
            Assert.IsTrue(expectedResult.SequenceEqual(result)  );
        }


        [TestMethod]
        public void Ordering_With_Two_Ascending_Expressions_Test()
        {
            _sut = Ordering<CorporateData>.Ascending(x => x.CompanyType).ThenByAscending(x=>x.CapitalIqId);
            var result = _sut.ToMongoSortBy().ToBson();
            var expectedResult = Builders<CorporateData>.Sort.Ascending(x => x.CompanyType).Ascending(x=>x.CapitalIqId).ToBson();
            Assert.IsTrue(expectedResult.SequenceEqual(result));
        }

        [TestMethod]
        public void Ordering_With_One_Ascending_And_One_Descending_Expressions_Test()
        {
            _sut = Ordering<CorporateData>.Ascending(x => x.CompanyType).ThenByDescending(x => x.CapitalIqId);
            var result = _sut.ToMongoSortBy().ToBson();
            var expectedResult = Builders<CorporateData>.Sort.Ascending(x => x.CompanyType).Descending(x => x.CapitalIqId).ToBson();
            Assert.IsTrue(expectedResult.SequenceEqual(result));
        }


        [TestMethod]
        public void Ordering_With_One_Descending_And_One_Descending_Expressions_Test()
        {
            _sut = Ordering<CorporateData>.Descending(x => x.CompanyType).ThenByDescending(x => x.CapitalIqId);
            var result = _sut.ToMongoSortBy().ToBson();
            var expectedResult = Builders<CorporateData>.Sort.Descending(x => x.CompanyType).Descending(x => x.CapitalIqId).ToBson();
            Assert.IsTrue(expectedResult.SequenceEqual(result));
        }
    }
}
